<template>
  <div class="policylibrary-last">
      <div class="hr10"></div>
      <Row :gutter="24">
          <Col span="24">时间：
            <DatePicker type="date" :value="startTime" @on-change="startTimeChange" placeholder="开始时间" style="width: 200px"></DatePicker>
              -
            <DatePicker type="date" :value="endTime" @on-change="endTimeChange"  placeholder="结束时间" style="width: 200px"></DatePicker>
            <Input type="text" placeholder="请输入关键字" v-model="title" style="width:200px;"/>
            <Button type="primary" @click="getpolicyData">搜索</Button>
          </Col>
      </Row>
      <div class="hr20"></div>
      <Row>
        <Col span="24">
          <Table :columns="columnList" :data="corporateDataList" size="large" :loading="loading"></Table>
          <div style="float: right; margin: 10px">
            <Page 
            :total="total" 
            :current.sync="currentPage" 
            :page-size="pageSize"              
            @on-change="changeLibraryPage" 
            show-total
            show-elevator 
            show-sizer 
            @on-page-size-change="selectPage"
            :page-size-opts="[10,20,50,100]"
            ></Page>
          </div>
        </Col>
      </Row>
  </div>
</template>

<script>
function filtercontent(str){
  str=str.replace(/\s+/g,""); //去除空格
  return str;
}
import store from '@/store/index'
  export default {
    name: "PolicyDeclareLast",
    store,
    data(){
      return{
        policy_library:'PolicyDeclareLast',
        loading:false,
        total:0,
        pageNum:1,
        currentPage:1,
        pageSize:10,
        title:'',
        telphone:'',
        startTime:"",//设置默认开始时间
        endTime:"",//结束时间   
        columnList:[
          {
            title:'标题',
            key:'title',
            align:'center',
            render:(h,params)=>{
              return h("div",{
                class:'policytitlecontent'
              },[
                h("div",
                 {
                   style:{
                     fontSize:'14px',
                     textAlign:'left'
                   },
                    on:{
                          click:()=>{
                            this.$router.push({path:'detail/type/1/id/'+params.row.id});
                          }
                    }
                 },params.row.title),
                h("div",
                 {
                   style:{
                     fontSize:'12px',
                     color:'#999999',
                     textAlign:'left'
                   },
                    on:{
                          click:()=>{                            
                            this.$router.push({path:'detail/type/1/id/'+params.row.id});
                          }
                    },
                   class:'policy-contentfilter'
                 },filtercontent(params.row.textContent)),
              ])
            }
          },{
            title:'发布时间',
            key:'publishDate',
            align:'center',
            width:120
          },{
              title:'操作',
              align:'center',
              width:150,
              render:(h,params)=>{
                  return h('div',[
                    h("Button",{
                      props:{
                          type:params.row.follow==1?'default':'primary',
                          size:'small'
                      },
                      style:{
                        marginRight:'10px'
                      },
                      on:{
                          click:()=>{                            
                            this.setfollow(params.row.id,params.row.follow==1?0:1);
                          }
                      }
                    },params.row.follow==1?"取消跟踪":"跟踪"),
                    h("Button",{
                      props:{
                          type:'primary',
                          size:'small'
                      },
                      on:{
                          click:()=>{                            
                            this.openconsulting(params.row.id);
                          }
                      }
                    },"咨询"),
                  ]);
              }
            }
        ],
        currentFollow:0,
        corporateDataList:[],

      }
    },
    components:{
        
    },
    methods:{
      //开始时间  默认2019-01-01
      startTimeChange(e){
        this.startTime=e;
      },
      //结束时间  默认是当天
      endTimeChange(e){
        this.endTime=e;
      },
      getpolicyData(){//列表数据
        if (this.loading) return; // 避免多次请求
        this.loading = true;
        let follow=999;
        let url=this.$url.baseUrl+'/consulting-library/api/policy/policy';
        this.$http.get(url,{
          params:{
            follow:follow,
            pageSize:this.pageSize,
            pageNum:this.pageNum,
            startTime:this.startTime,
            endTime:this.endTime,
            title:this.title
          }
        }).then(response =>{
            let result=response.data
            if (result.meta.success){
              //console.log(result.data);
              this.loading = false;
              this.corporateDataList=result.data.list;
              this.total=result.data.total;
              this.title='';
              this.startTime='';
              this.endTime='';
            }else {
              console.log("获取数据失败")
            }
        })
      },
      changeLibraryPage(index){
        this.pageNum=index;
        console.log(index,'this.pageNum');
        this.getpolicyData(this.pageNum)
      },
      selectPage(index){
        this.pageSize=index;
        this.getpolicyData(this.pageNum)
        console.log(index,'this.pageSize');
      },
      setfollow(id,follow){        
        let url=this.$url.baseUrl+'/consulting-library/api/policy/follow?id='+id+'&follow='+follow;
        this.$http.get(url).then(response =>{
            let result=response.data
            if (result.meta.success){
              this.$Message.success(result.data, 3);
              this.getpolicyData();//更新列表数据
            }else {
              this.$Notice.warning({
                    title: '抱歉，您的跟踪数量已达上限',
                    desc: '请前往“跟踪设置”进行取消跟踪操作',
                    duration: 3
              });
              console.log("获取数据失败");
            }
        })
      },
      openconsulting(telphone){//咨询
        this.$Modal.confirm({
            content: '<p>项目申报请联系：科技日报社技术研发部</p><p>电话：'+telphone+'</p>',
            onOk: () => {
                //this.$Message.info('Clicked ok');
            },
            onCancel: () => {
                //this.$Message.info('Clicked cancel');
            }
        });
      }
    },
    mounted() {
      this.getpolicyData();
      this.$store.state.hidemenu=true;//显示菜单项
      this.$store.state.submenuname='PolicyDeclareLast';//选中
    },
    watch:{

    },
    created(){

    }

  }
</script>
<style>
.policy-contentfilter{
  overflow : hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.policy-titlefilter{
  overflow : hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}
.policytitlecontent{
  padding:8px 0;
  cursor: pointer;
}
</style>
<style rel="stylesheet/less" lang="less" scoped>
.displayflex(){
  -webkit-display: flex;
  -moz-display: flex;
  display: flex;
}
.flexdiv(){
  -webkit-flex:1;
  -moz-flex:1;
  flex:1;
}
.hr10{
  height: 10px;
  line-height: 0;
  font-size: 0;
}
.hr20{
  height: 20px;
  line-height: 0;
  font-size: 0;
}
.policy-layout{
  .displayflex();
}
.policy-left{
  width:60px;  
  .ivu-menu{
    width:60px!important;
  }
  .layout-nav{
    width:60px;
    overflow: hidden;
  }
  .ivu-menu-vertical.ivu-menu-light:after{
    display: none;
  }
  .ivu-menu-light.ivu-menu-vertical .ivu-menu-item-active:not(.ivu-menu-submenu):after{
    display: none;
  }
  .ivu-menu-light.ivu-menu-vertical .ivu-menu-item-active:not(.ivu-menu-submenu){
    background-color: #eeeeee;
    color: #333333;
  }
}
.policy-right{
  padding:0 10px 10px 10px;
  .layout-assistant{
      height: inherit;
  }
  .policy-ivu-tab{
    .displayflex();
    height: 35px;
    overflow: hidden;
  }
  .ivu-menu-horizontal{
    height: 45px;
    line-height: 45px;
  }
  .ivu-menu-horizontal .ivu-menu-item, .ivu-menu-horizontal .ivu-menu-submenu{
    padding:0 3px;
    margin-right: 30px;
  }
}
  .flex-inline{
    display: flex;
  }
  .title{
    font-size: 16px;
    font-weight: 700;
    line-height: 40px;
    margin-right: 10px;
  }
  .ivu-tabs-nav-scroll{
    width: 830px;
  }
  .tagItem{
    padding: 0 10px;
    line-height: 40px;
    display: inline-block;
    font-size: 14px;
    font-weight: 500;
    position: relative;
    box-sizing: border-box;
    border: none;
    background: #ffffff;
    height: 40px;
    margin: 0px;
  }
  .tagsList .ivu-tabs-bar{
    margin-bottom: 0px;
    border:none;
  }
  .tagsList .ivu-tabs-content{
    display: none;
  }
  .ivu-form-item{
    display: inline-block;
    margin-right: 20px;
  }
  .ivu-btn > .ivu-icon{
    line-height: 1;
    font-size: 20px;
  }
</style>
